🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / domain / src / commonMain / kotlin / org / meshtastic / core / domain / usecase / settings / AdminActionsUseCase.kt
Displaying Raw • Download
core/domain/src/commonMain/kotlin/org/meshtastic/core/domain/usecase/settings/AdminActionsUseCase.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 4.52 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.domain.usecase.settings
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.repository.NodeRepository
Tff7b72import T7ee787org.meshtastic.core.repository.RadioController
T8b949e/**
* Use case for performing administrative and destructive actions on mesh nodes.
*
* This component provides methods for rebooting, shutting down, or resetting nodes within the mesh. It also handles
* local database synchronization when these actions are performed on the locally connected device.
*
* Each method's `onRequestId` callback fires with the request's packet ID *before* the send is issued; callers that
* correlate responses by request ID must register there (see [RadioConfigUseCase] for the ordering rationale).
*/
Tf0883e@Single
Tff7b72open Tff7b72class T56d364AdminActionsUseCase
Tff7b72constructorTb4b4b4(
Tff7b72private Tff7b72val Te6edf3radioControllerTb4b4b4: Te6edf3RadioControllerTb4b4b4,
Tff7b72private Tff7b72val Te6edf3nodeRepositoryTb4b4b4: Te6edf3NodeRepositoryTb4b4b4,
Tb4b4b4) Tb4b4b4{
T8b949e/**
* Reboots the radio.
*
* @param destNum The node number to reboot.
* @return The packet ID of the request.
*/
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8ffrebootTb4b4b4(Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3onRequestIdTb4b4b4: Tb4b4b4(Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4)Tb4b4b4: Tffa657Int Tb4b4b4{
Tff7b72val Te6edf3packetId Tff7b72= Te6edf3radioControllerTb4b4b4.Te6edf3generatePacketIdTb4b4b4(Tb4b4b4)
Te6edf3onRequestIdTb4b4b4(Te6edf3packetIdTb4b4b4)
Te6edf3radioControllerTb4b4b4.Te6edf3rebootTb4b4b4(Te6edf3destNumTb4b4b4, Te6edf3packetIdTb4b4b4)
Tff7b72return Te6edf3packetId
Tb4b4b4}
T8b949e/**
* Shuts down the radio.
*
* @param destNum The node number to shut down.
* @return The packet ID of the request.
*/
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8ffshutdownTb4b4b4(Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3onRequestIdTb4b4b4: Tb4b4b4(Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4)Tb4b4b4: Tffa657Int Tb4b4b4{
Tff7b72val Te6edf3packetId Tff7b72= Te6edf3radioControllerTb4b4b4.Te6edf3generatePacketIdTb4b4b4(Tb4b4b4)
Te6edf3onRequestIdTb4b4b4(Te6edf3packetIdTb4b4b4)
Te6edf3radioControllerTb4b4b4.Te6edf3shutdownTb4b4b4(Te6edf3destNumTb4b4b4, Te6edf3packetIdTb4b4b4)
Tff7b72return Te6edf3packetId
Tb4b4b4}
T8b949e/**
* Factory resets the radio.
*
* @param destNum The node number to reset.
* @param isLocal Whether the reset is being performed on the locally connected node.
* @return The packet ID of the request.
*/
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8fffactoryResetTb4b4b4(Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3isLocalTb4b4b4: Tffa657BooleanTb4b4b4, Te6edf3onRequestIdTb4b4b4: Tb4b4b4(Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4)Tb4b4b4: Tffa657Int Tb4b4b4{
Tff7b72val Te6edf3packetId Tff7b72= Te6edf3radioControllerTb4b4b4.Te6edf3generatePacketIdTb4b4b4(Tb4b4b4)
Te6edf3onRequestIdTb4b4b4(Te6edf3packetIdTb4b4b4)
Te6edf3radioControllerTb4b4b4.Te6edf3factoryResetTb4b4b4(Te6edf3destNumTb4b4b4, Te6edf3packetIdTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3isLocalTb4b4b4) Tb4b4b4{
T8b949e// If it's the local node, we should also clear the phone's node database as it will be out of sync.
Te6edf3nodeRepositoryTb4b4b4.Te6edf3clearNodeDBTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tff7b72return Te6edf3packetId
Tb4b4b4}
T8b949e/**
* Syncs the node's real-time clock to the phone's current time.
*
* Lets a user correct a remote node whose RTC has drifted without being on-site or using the CLI.
*
* @param destNum The node number to update.
* @return The packet ID of the request.
*/
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8ffsetTimeTb4b4b4(Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3onRequestIdTb4b4b4: Tb4b4b4(Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4)Tb4b4b4: Tffa657Int Tb4b4b4{
Tff7b72val Te6edf3packetId Tff7b72= Te6edf3radioControllerTb4b4b4.Te6edf3generatePacketIdTb4b4b4(Tb4b4b4)
Te6edf3onRequestIdTb4b4b4(Te6edf3packetIdTb4b4b4)
Te6edf3radioControllerTb4b4b4.Te6edf3setTimeTb4b4b4(Te6edf3destNumTb4b4b4, Te6edf3packetIdTb4b4b4)
Tff7b72return Te6edf3packetId
Tb4b4b4}
T8b949e/**
* Resets the NodeDB on the radio.
*
* @param destNum The node number to reset.
* @param preserveFavorites Whether to keep favorite nodes in the database.
* @param isLocal Whether the reset is being performed on the locally connected node.
* @return The packet ID of the request.
*/
Tff7b72open Tff7b72suspend Tff7b72fun Td2a8ffnodedbResetTb4b4b4(
Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4,
Te6edf3preserveFavoritesTb4b4b4: Tffa657BooleanTb4b4b4,
Te6edf3isLocalTb4b4b4: Tffa657BooleanTb4b4b4,
Te6edf3onRequestIdTb4b4b4: Tb4b4b4(Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657Unit Tff7b72= Tb4b4b4{Tb4b4b4}Tb4b4b4,
Tb4b4b4)Tb4b4b4: Tffa657Int Tb4b4b4{
Tff7b72val Te6edf3packetId Tff7b72= Te6edf3radioControllerTb4b4b4.Te6edf3generatePacketIdTb4b4b4(Tb4b4b4)
Te6edf3onRequestIdTb4b4b4(Te6edf3packetIdTb4b4b4)
Te6edf3radioControllerTb4b4b4.Te6edf3nodedbResetTb4b4b4(Te6edf3destNumTb4b4b4, Te6edf3packetIdTb4b4b4, Te6edf3preserveFavoritesTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3isLocalTb4b4b4) Tb4b4b4{
T8b949e// If it's the local node, we should also clear the phone's node database.
Te6edf3nodeRepositoryTb4b4b4.Te6edf3clearNodeDBTb4b4b4(Te6edf3preserveFavoritesTb4b4b4)
Tb4b4b4}
Tff7b72return Te6edf3packetId
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.07s